package com.kkb.test;

import com.kkb.pojo.Team;

import java.sql.*;
import java.time.temporal.TemporalAmount;
import java.util.ArrayList;
import java.util.List;

public class OriginJDBC {
    public static void main(String[] args) throws SQLException {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/mybatis?serverTimezone=GMT";
            String user = "root";
            String password = "123456";
            conn = DriverManager.getConnection(url, user, password);
            String sql = "select * from team";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            List<Team> list = new ArrayList<>();
            while (rs.next()){
                Team team = new Team();
                team.setTeamId(rs.getInt("teamId"));
                team.setTeamName(rs.getString("teamName"));
                team.setLocation(rs.getString("location"));
                team.setCreateTime(rs.getDate("createTime"));
                list.add(team);
            }
            for (Team t:list) {
                System.out.println(t);
            }
        } catch (Exception throwables) {
            throwables.printStackTrace();
        }finally {
            if (conn!=null){
                conn.close();
            }
            if (ps!=null){
                ps.close();
            }
            if (rs!=null){
                rs.close();
            }
        }
    }
}
